import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:dio/dio.dart';
import 'package:short_video/entity/home/video_list_entity.dart';
import '../../network/base_entity.dart';
import '../../network/http_manager.dart';
import '../../network/http_entity.dart';
import '../../utils/color_util.dart';

class PublishViewModel extends ChangeNotifier {
  TextEditingController introduceController = TextEditingController();
  void exit(BuildContext context) {
    showCupertinoDialog(
        context: context,
        builder: (BuildContext context) {
          return CupertinoAlertDialog(
            title: const Text(
              "发布",
              style: TextStyle(
                fontSize: 16,
                color: ColorsUtil.COLOR_333333,
              ),
            ),
            content: const Text(
              "已发布成功，要退出吗？",
              style: TextStyle(
                fontSize: 15,
                color: ColorsUtil.COLOR_666666,
              ),
            ),
            actions: <Widget>[
              CupertinoDialogAction(
                child: const Text(
                  "取消",
                  style: TextStyle(
                    fontSize: 15,
                    color: ColorsUtil.COLOR_666666,
                  ),
                ),
                onPressed: () {
                  Navigator.pop(context);
                },
              ),
              CupertinoDialogAction(
                child: const Text(
                  "确定",
                  style: TextStyle(
                    fontSize: 15,
                    color: ColorsUtil.COLOR_FF5C5C,
                  ),
                ),
                onPressed: () {
                  Navigator.pop(context);
                  Navigator.pop(context);
                },
              ),
            ],
          );
        });
  }
  void publish(BuildContext context, XFile file) async {
    // debugPrint("publish---${file.name}----");
    // debugPrint("publish---${file.path}----");
    // IBaseEntity response = await HttpManager.getInstance().uploadFile(file.path, name: file.name, businessCode: "SKU");
    // debugPrint("${response.getMsg()}");


    //response = response as HttpEntity;
    var respon = HttpManager.getInstance().request(url: "https://dev.videoapi.yunjixiaodian.com/api/app/video/publish",
        params:  {"imgUrl": "https://book.flutterchina.club/assets/img/logo.png", "title": "1234士大夫士大夫胜多负少", "videoUrl": file.path,
        },
        header: {"groupcode":"JDY2207268668",});
    //debugPrint("publish---${response.toString()}----");
    exit(context);




    // VideoEntity entity = VideoEntity.fromJson(response?.getData());
    //
    // debugPrint("${entity.title}");
    // IBaseEntity? result = await HttpManager.getInstance().request(url: "https://dev.videoapi.yunjixiaodian.com/api/app/video/publish",
    // params:  {"imgUrl": "https://book.flutterchina.club/assets/img/logo.png", "title": "1234士大夫士大夫胜多负少", "videoUrl": r,
    // },
    // header: {"groupcode":"JDY2207268668",});
    //debugPrint("publish---${response.}----");
  }
}

// var response = HttpManager.getInstance().request(url: "https://dev.videoapi.yunjixiaodian.com/api/app/video/publish",
//     params:  {"imgUrl": "https://book.flutterchina.club/assets/img/logo.png", "title": "1234士大夫士大夫胜多负少", "videoUrl": file.path,
//     },
//     header: {"groupcode":"JDY2207268668",});
// debugPrint("publish---${response.toString()}----");
